import java.io.IOException;
import java.net.ServerSocket;
import java.net.SocketException;

public class NormalConnectionHandler extends Thread {
    
    // Port where the server socket should listen
    public int port;
    // The server socket used to accept the connections
    public static ServerSocket server_socket;
    
    public NormalConnectionHandler(int port) {
        this.port = port;
    }
    
    public void run() {
        MainWindow.window.addLogEntry("Normal Connection Handler started");
        try {
            NormalConnectionHandler.server_socket = new ServerSocket(port);
            while (!NormalConnectionHandler.server_socket.isClosed()) {
                HTTPHandler h = new HTTPHandler(NormalConnectionHandler.server_socket.accept());
                h.run();
            }
        } catch (IOException e) {
            System.err.println("ERROR: Problem launching HTTP handling thread.");
        }
        
        MainWindow.window.addLogEntry("Normal Connection Handler stopped");
    }
}
